<?php $auth=0; ?>
<?php include 'lib/includes.php'; ?>
<?php include 'partials/header_menu.php'; ?>
<?php 
/*
*suppression client
*/

if(isset($_GET['delete']))
{
	$id=$db->quote($_GET['delete']);
	$db->query("delete from client where clientId=$id");
	?>
<?php
}
?>
<?php
/*
*affichage des clients
*/
$select=$db->query('select clientId,clientNom,clientPrenom,clientPhone,clientMail,creditcard,clientCredidate from client');
$clients=$select->fetchAll();
?>
<br>
<br>
<h3><span class="titre">&nbsp;La liste des clients</span></h3>
<br>
<p>&nbsp;&nbsp;<a href="user_edit.php" class="btn btn-success">ajouter un nouveau client <span  class="glyphicon glyphicon-plus"></span></a><p>
<div id="client" style="width: 100%; height: 380px;"></div>
	<script>var i=0;</script>
	<?php  foreach($clients as $client){ 
	//echo json_encode($soc); 
	?>
	<script>
	var sup='<a href="user_edit.php?id=<?php echo($client['clientId']); ?>" class="glyphicon glyphicon-edit">&nbsp;editer</a>&nbsp;&nbsp;<a href="user.php?delete=<?php echo($client['clientId']); ?>" class="glyphicon glyphicon-remove" onclick="">&nbsp;supprimer</a>&nbsp;&nbsp;<a href="write_php.php?mail=<?php echo($client['clientMail']); ?>"class="glyphicon glyphicon-envelope">&nbsp;écrire</a>';
	i++;
	$('#client').w2grid({
    name: 'grid',
    header: 'Liste des clients',
    show: {
        toolbar: true,
        footer: true
    },
    columns: [
        { field: 'recid', caption: 'ID', size: '5%', sortable: true, attr: 'align=center' },
        { field: 'ID', caption: 'ID du client', size: '5%', sortable: true, resizable: true },
		{ field: 'Nom', caption: 'Nom', size: '10%', sortable: true, resizable: true },
		{ field: 'Prenom', caption: 'Prénom', size: '10%', sortable: true, resizable: true },
        { field: 'Portable', caption: 'Portable', size: '10%', resizable: true },
        { field: 'Mail', caption: 'Mail', size: '10%', resizable: true },
		{ field: 'carte', caption: 'Carte de crédit', size: '10%', resizable: true },
		{ field: 'Date', caption: 'Date dexpiration', size: '5%', resizable: true },
		{ field: 'link', caption: 'Action', size: '15%', resizable: true },
    ],
    searches: [
        { field: 'ID', caption: 'ID', type: 'text' },
        { field: 'Nom', caption: 'Nom', type: 'text' },
        { field: 'Prenom', caption: 'Prénom', type: 'text' },
		{ field: 'Portable', caption: 'Portable', type: 'text' },
		{ field: 'Mail', caption: 'Mail', type: 'text' },
		{ field: 'Date', caption: 'Date', type: 'text' },
    ],
    sortData: [{ field: 'ID', direction: 'ASC' }]
    });
	w2ui['grid'].add({ recid:  i ,ID: <?php echo($client['clientId']); ?> , Nom: '<?php echo($client['clientNom']); ?>' , Prenom: '<?php echo($client['clientPrenom']); ?>', Portable: '<?php echo($client['clientPhone']); ?>',Mail : '<?php echo($client['clientMail']); ?>',carte : '<?php echo($client['creditcard']); ?>',Date : '<?php echo($client['clientCredidate']); ?>',link:sup });
	</script>
	
<?php } ?>	
<br>
<?php include 'partials/footer.php'; ?>
